package cn.baiweigang.uu.db.mapper;

import cn.baiweigang.uu.db.dataobj.StockInfoDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BaseInfoMapper {

    @Select("select * from stock_base_info order by dm ")
    public List<StockInfoDo> queryAll();

    @Select("select * from stock_base_info where dm=#{dm} ")
    public StockInfoDo queryByDm(@Param("dm") String dm);

    @Insert({"<script>",
            "insert into stock_base_info(dm,mc,jys,ds) values",
            "(#{dm},#{mc},#{jys},#{ds})",
            "ON DUPLICATE KEY UPDATE",
            "<trim prefix=\"\" suffixOverrides=\"\">",
            "updatetime =NOW(),ds = #{ds},mc= #{mc}",
            "</trim>",
            "</script>"
    })
    public void insertOrUpdate(StockInfoDo stockInfoDo);

    @Insert({"<script>",
            "insert into stock_base_info(dm,mc,jys,ds) values",
            "<foreach collection='stockInfoDoList' item='stockInfoDo' index='index' separator=','>",
            "(#{stockInfoDo.dm},#{stockInfoDo.mc},#{stockInfoDo.jys},#{stockInfoDo.ds})",
            "</foreach>",
            "ON DUPLICATE KEY UPDATE",
            "<trim prefix=\"\" suffixOverrides=\"\">",
            "updatetime =NOW(),ds = values(ds),mc = values(mc)",
            "</trim>",
            "</script>"

    })
    public void insertOrUpdateBatch(@Param(value = "stockInfoDoList") List<StockInfoDo> stockInfoDoList);

    @Select("select * from stock_base_info where jys='sh' or jys='sz' order by dm ")
    public List<StockInfoDo> queryCN();

    @Select("select * from stock_base_info where jys='sh' or jys='sz' order by dm  limit #{start},#{num}")
    public List<StockInfoDo> queryCNLimit(@Param("start") int start,@Param("num") int num);
}
